home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / music / dsik_pas.zip / SOUND.PAS < prev    next >
Pascal/Delphi Source File  |  1994-07-28  |  6KB  |  250 lines

  1. (*  sound.pas - Digital Sound Interface Kit V1.01a unit file
  2.  
  3.     Copyright 1993,94 Carlos Hasan
  4. *)
  5.  
  6. unit Sound;
  7.  
  8. interface
  9.  
  10. const
  11.   (* Misc Values *)
  12.   MAXVOICES   = 16;
  13.   MAXTRACKS   = 16;
  14.   MAXSAMPLES  = 100;
  15.   MAXORDERS   = 128;
  16.   MINPERIOD   = 28;
  17.   MAXPERIOD   = 6848;
  18.   MIDCPERIOD  = 428;
  19.   MIDCFREQ    = 8363;
  20.  
  21.   (* Sound Cards *)
  22.   ID_NONE     = 0;
  23.   ID_SB       = 1;
  24.   ID_SB201    = 2;
  25.   ID_SBPRO    = 3;
  26.   ID_SB16     = 4;
  27.   ID_GUS      = 5;
  28.  
  29.   (* Types of RAM *)
  30.   RAM_NONE    = 0;
  31.   RAM_SYSTEM  = 1;
  32.   RAM_CARD    = 2;
  33.  
  34.   (* Error Values *)
  35.   ERR_OK      = 0;
  36.   ERR_NORAM   = 1;
  37.   ERR_NODRAM  = 2;
  38.   ERR_NOFILE  = 3;
  39.   ERR_FORMAT  = 4;
  40.   ERR_ACCESS  = 5;
  41.  
  42.   (* Playing Status *)
  43.   PS_STOPPED  = 0;
  44.   PS_PLAYING  = 1;
  45.   PS_PAUSED   = 2;
  46.  
  47.   (* Pattern Break Values *)
  48.   PB_NONE     = 0;
  49.   PB_BREAK    = 1;
  50.   PB_JUMP     = 2;
  51.  
  52.   (* DSM File Block IDs *)
  53.   ID_RIFF     = $46464952;
  54.   ID_DSMF     = $464D5344;
  55.   ID_SONG     = $474E4F53;
  56.   ID_INST     = $54534E49;
  57.   ID_PATT     = $54544150;
  58.  
  59.   (* WAV File Block IDs *)
  60.   ID_WAVE     = $45564157;
  61.   ID_FMT      = $20746D66;
  62.   ID_DATA     = $61746164;
  63.  
  64.   (* Panning Values *)
  65.   PAN_LEFT    = $00;
  66.   PAN_RIGHT   = $80;
  67.   PAN_DOLBY   = $A4;
  68.  
  69.   (* Inst Bit Flags *)
  70.   INST_LOOPED = $01;
  71.   INST_SIGNED = $02;
  72.   INST_PACKED = $04;
  73.  
  74. type
  75.   (* Basic Data Types *)
  76.   dword = longint;
  77.  
  78.   (* RIFF Block Header Formats *)
  79.   DSMHeader = record
  80.     ID          : dword;
  81.     Length      : dword;
  82.     FileType    : dword;
  83.   end;
  84.  
  85.   DSMBlock = record
  86.     ID          : dword;
  87.     Length      : dword;
  88.   end;
  89.  
  90.   (* DSM File Block Formats *)
  91.   DSMSong = record
  92.     SongName    : array [0..27] of char;
  93.     Version     : word;
  94.     Flags       : word;
  95.     Pad         : dword;
  96.     NumOrders   : word;
  97.     NumSamples  : word;
  98.     NumPatterns : word;
  99.     NumChannels : word;
  100.     GlobalVolume: byte;
  101.     MasterVolume: byte;
  102.     InitTempo   : byte;
  103.     InitBPM     : byte;
  104.     ChanMap     : array [0..Pred(MAXTRACKS)] of byte;
  105.     Orders      : array [0..Pred(MAXORDERS)] of byte;
  106.   end;
  107.  
  108.   PDSMInst = ^DSMInst;
  109.   DSMInst = record
  110.     FileName    : array [0..12] of char;
  111.     Flags       : word;
  112.     Volume      : byte;
  113.     Length      : dword;
  114.     LoopStart   : dword;
  115.     LoopEnd     : dword;
  116.     Address     : pointer;
  117.     MidCRate    : word;
  118.     Period      : word;
  119.     SampleName  : array [0..27] of char;
  120.   end;
  121.  
  122.   PDSMPatt = ^DSMPatt;
  123.   DSMPatt = record
  124.     Length      : word;
  125.     Data        : array [0..0] of byte;
  126.   end;
  127.  
  128.   (* WAV File Block Formats *)
  129.   DSMWave = record
  130.     SampleFormat: word;
  131.     NumChannels : word;
  132.     PlayRate    : dword;
  133.     BytesPerSec : dword;
  134.     Pad         : word;
  135.     BitsPerSmpl : word;
  136.   end;
  137.  
  138.   (* Internal DSM format *)
  139.   PDSM = ^DSM;
  140.   DSM = record
  141.     Song        : DSMSong;
  142.     Inst        : array [0..Pred(MAXSAMPLES)] of PDSMInst;
  143.     Patt        : array [0..Pred(MAXORDERS)] of PDSMPatt;
  144.   end;
  145.  
  146.   (* Sound Card Configuration *)
  147.   DSMCard = record
  148.     CardID      : byte;
  149.     Flags       : byte;
  150.     IOAddr      : word;
  151.     IRQNum      : byte;
  152.     DRQNum      : byte;
  153.     MixRate     : word;
  154.   end;
  155.  
  156.   (* Internal Track structure *)
  157.   Track = record
  158.     NoteEvent   : word;
  159.     VolumeEvent : byte;
  160.     Note        : byte;
  161.     Sample      : byte;
  162.     Volume      : byte;
  163.     Effect      : word;
  164.     Period      : word;
  165.     WantedPeriod: word;
  166.     Rate        : word;
  167.     VibrPos     : byte;
  168.     VibrParm    : byte;
  169.     TremPos     : byte;
  170.     TremParm    : byte;
  171.     ToneSpeed   : byte;
  172.     EQBar       : byte;
  173.     ArpTable    : array [0..2] of word;
  174.   end;
  175.  
  176.   (* Internal Music structure *)
  177.   PDSMMusicInfo = ^DSMMusicInfo;
  178.   DSMMusicInfo = record
  179.     ActiveTracks  : word;
  180.     Tracks        : array [0..Pred(MAXTRACKS)] of Track;
  181.     OrderPosition : byte;
  182.     OrderLength   : byte;
  183.     PatternNumber : byte;
  184.     PatternRow    : byte;
  185.     BreakFlag     : byte;
  186.     Tempo         : byte;
  187.     TempoCount    : byte;
  188.     BPM           : byte;
  189.     CardStatus    : word;
  190.     PlayStatus    : word;
  191.     SongPtr       : pointer;
  192.     SyncMark      : byte;
  193.   end;
  194.  
  195. (* Sound System API Routines *)
  196. function DSMInit(var Card:DSMCard):boolean;
  197. procedure DSMDone;
  198. procedure DSMPoll;
  199. procedure DSMSetupVoices(MaxVoices:word; MasterVolume:word);
  200. procedure DSMStopVoices;
  201. function DSMTypeOfRAM:word;
  202. function DSMAllocSampleData(Inst:PDSMInst):boolean;
  203. procedure DSMFreeSampleData(Inst:PDSMInst);
  204. procedure DSMPlaySample(Voice:word; Inst:PDSMInst);
  205. procedure DSMStopSample(Voice:word);
  206. procedure DSMSetPeriod(Voice:word; Period:word);
  207. procedure DSMSetVolume(Voice:word; Volume:word);
  208. procedure DSMSetBalance(Voice:word; Balance:word);
  209. procedure DSMSetMusicVolume(Volume:word);
  210. procedure DSMSetSoundVolume(Volume:word);
  211. procedure DSMPlayMusic(Module:PDSM);
  212. procedure DSMStopMusic;
  213. function DSMGetMusicStatus:word;
  214. function DSMGetMusicInfo:PDSMMusicInfo;
  215.  
  216. implementation
  217.  
  218. {$L SB.OBJ}
  219. {$L GUS.OBJ}
  220. {$L NULL.OBJ}
  221. {$L AUDIO.OBJ}
  222. {$L PLAYER.OBJ}
  223.  
  224. (* Sound Devices Internal Interfaces *)
  225. procedure SBAudioDevice; external;
  226. procedure GUSAudioDevice; external;
  227. procedure NULLAudioDevice; external;
  228.  
  229. function DSMInit(var Card:DSMCard):boolean; external;
  230. procedure DSMDone; external;
  231. procedure DSMPoll; external;
  232. procedure DSMSetupVoices(MaxVoices:word; MasterVolume:word); external;
  233. procedure DSMStopVoices; external;
  234. function DSMTypeOfRAM:word; external;
  235. function DSMAllocSampleData(Inst:PDSMInst):boolean; external;
  236. procedure DSMFreeSampleData(Inst:PDSMInst); external;
  237. procedure DSMPlaySample(Voice:word; Inst:PDSMInst); external;
  238. procedure DSMStopSample(Voice:word); external;
  239. procedure DSMSetPeriod(Voice:word; Period:word); external;
  240. procedure DSMSetVolume(Voice:word; Volume:word); external;
  241. procedure DSMSetBalance(Voice:word; Balance:word); external;
  242. procedure DSMSetMusicVolume(Volume:word); external;
  243. procedure DSMSetSoundVolume(Volume:word); external;
  244. procedure DSMPlayMusic(Module:PDSM); external;
  245. procedure DSMStopMusic; external;
  246. function DSMGetMusicStatus:word; external;
  247. function DSMGetMusicInfo:PDSMMusicInfo; external;
  248.  
  249. end.
  250.